package com.qf.java2102.qihaonan.hotel.service.impl;

import com.qf.java2102.qihaonan.hotel.constant.MessageConstant;
import com.qf.java2102.qihaonan.hotel.dao.IDinnerTableDao;
import com.qf.java2102.qihaonan.hotel.dao.IFoodTypeDao;
import com.qf.java2102.qihaonan.hotel.dao.impl.DinnerTableDaoImpl;
import com.qf.java2102.qihaonan.hotel.dao.impl.FoodTypeDaoImpl;
import com.qf.java2102.qihaonan.hotel.entity.ResultVO;
import com.qf.java2102.qihaonan.hotel.pojo.DinnerTable;
import com.qf.java2102.qihaonan.hotel.pojo.FoodType;
import com.qf.java2102.qihaonan.hotel.service.IDinnerTableService;
import com.qf.java2102.qihaonan.hotel.utils.JdbcUtils;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author qhn
 * @version 1.0
 */
public class DinnerTableServiceImpl implements IDinnerTableService {

    private IDinnerTableDao dinnerTableDao = new DinnerTableDaoImpl();
    private IFoodTypeDao foodTypeDao = new FoodTypeDaoImpl();

    @Override
    public ResultVO<Map> findByTableStatus(Integer status) {

        try {
            Map<String, Object> data = new HashMap<>();
            List<DinnerTable> tables = dinnerTableDao.findByTableStatus(status);
            data.put("tables", tables);
            //菜系列表
            List<FoodType> foodTypeList = foodTypeDao.findAll();
            data.put("types", foodTypeList);

            return ResultVO.ok(MessageConstant.QUERY_DINNER_TABLE_SUCCESS, data);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JdbcUtils.release(JdbcUtils.getConnection());
        }
        return ResultVO.error(MessageConstant.QUERY_DINNER_TABLE_FAIL);
    }
}
